//
//  Triangle.m
//  GLPaint
//
//  Created by Brian Kong on 2/25/12.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//
#import "Triangle.h"
#import "PaintingView.h"


static GLfloat linesVertices[] = { 
   /* 00 */ 0.0, 0.0, 0.0,  /* line 1 */
   /* 03 */ 0.0, 0.0, 0.0,
   /* 06 */ 0.0, 0.0, 0.0,  /* line 2 */
   /* 09 */ 0.0, 0.0, 0.0,
   /* 12 */ 0.0, 0.0, 0.0,  /* line 3 */
   /* 15 */ 0.0, 0.0, 0.0,
};

static GLshort linesVerticesIndices[] = {
   0, 1, 2, 3, 3, 4
};
                    

///////////////////////////////////////////
@implementation Triangle

@synthesize delegate=m_Delegate;

-(id) init {
  if( [super init]==nil ) {
    return nil;
  }

  return self;
}

-(void) drawAtPoint:(CGPoint) point {

}


-(void) createTriangleMedians:(GLfloat *) v {
   int i,j;

   for(i=0, j=0; i<6; i+=2, j++) {
      linesVertices[i] = v[j];
   }

   CGPoint p0 = { (v[3]+v[6])/2, (v[4]+v[7])/2 };  /* vertices 1, 2 */
   CGPoint p1 = { (v[0]+v[9])/2, (v[1]+v[10])/2 }; /* vertices 0, 2 */
   CGPoint p2 = { (v[0]+v[3])/2, (v[1]+v[4])/2 };  /* vertices 0, 1 */

   linesVertices[3] = p0.x;
   linesVertices[4] = p0.y;

   linesVertices[9] = p1.x;
   linesVertices[10] = p1.y;

   linesVertices[15] = p2.x;
   linesVertices[16] = p2.y;
}

-(void) drawInRect:(CGRect) rect {

   /**
    * get OpenGL parms from Shape data source delegate
    */
  GLint StartingIndex = [[self delegate] shapeStartingIndex];
  GLsizei NumberOfIndices = [[self delegate] shapeNumberOfIndicesToRender];
  GLfloat *Vertices = [[self delegate] shapeVertices];

  glVertexPointer(3, GL_FLOAT, 0, Vertices);
  glDrawArrays(GL_LINE_LOOP, StartingIndex, NumberOfIndices);

  glVertexPointer(3, GL_FLOAT, 0, linesVertices);
  glDrawArrays(GL_LINES, 0, 1);
}

@end
